#ifndef FACEDETECTION_H
#define FACEDETECTION_H

#include <QMainWindow>
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>

QT_BEGIN_NAMESPACE
namespace Ui { class facedetection; }
QT_END_NAMESPACE

class facedetection : public QMainWindow
{
    Q_OBJECT

public:
    facedetection(QWidget *parent = nullptr);
    ~facedetection();


    void requestNetwork(QString url, QByteArray requestData, int opt);

    void addGroup();
    void addFace(QImage image, QString user_name);
    void searchFace(QImage image);

    void getUserList();
    void getUserInfo(QString user_id);
    void delFace(QString user_id);
    void delFaceByName(QString user_name);

    QString curUserName = "";
    QString curUserId = "";
    bool findFlag = false;

private:
    QNetworkAccessManager *manager;

    /* 获取token的接口URL*/
    const QString token_org = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=%1&client_secret=%2&";

    /* 存储serverapi地址 */
    QString serverApiUrl;

    /* 百度服务器API接口URL */
    const QString server_api = "https://aip.baidubce.com/rest/2.0/face/v3/%1?access_token=%2";


    /* 填写网页上申请的appkey  */
    const QString api_key = "7ZL1oK0FGXShx5UkimC0TZQj";
    const QString secret_key = "aVBjXs8uyoP9zHGRnLaKqzuoB8NGere3";

    /* 访问权限token */
    QString accessToken;

    /* 测试人脸token */
    const QString face_token = "0b750be4fe3584fd65e677fe8b43c3bd"; //jay
    const QString group_id = "0624_1835";

public slots:

    /* 响应完成处理 */
    void replyFinished();

    void readReadAddGroup();

    void readReadAddFace();

    void readReadSearchFace();

    void readReadUserList();

    void readReadUserList2();

    void readReadUserInfo();

    void readReadUserDel();

signals:
    void faceRes(int, bool, QString);


private:
    Ui::facedetection *ui;
};
#endif // FACEDETECTION_H
